package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.entity.Admin_Feedbackresponse_Info;
import com.example.computer_exam_training_sys.service.Admin_feedbackresponse_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedback_responses")
@CrossOrigin
public class Admin_Feedbackresponse_Controller {
    @Autowired
    private Admin_feedbackresponse_Service feedbackresponseService;

    // 获取所有反馈回复（分页，page和pageSize均由前端传入，且必须传）
    @GetMapping("/findAll")
    public List<Admin_Feedbackresponse_Info> findAllResponses(@RequestParam int page, @RequestParam int pageSize) {
        return feedbackresponseService.findAllResponsesByPage(page, pageSize);
    }

    // 根据反馈ID获取所有回复（分页，page和pageSize均由前端传入，且必须传）
    @GetMapping("/feedback/{feedback_id}")
    public List<Admin_Feedbackresponse_Info> getResponsesByFeedbackId(@PathVariable("feedback_id") int feedback_id,
                                                                     @RequestParam int page,
                                                                     @RequestParam int pageSize) {
        return feedbackresponseService.getResponsesByFeedbackIdByPage(feedback_id, page, pageSize);
    }

    // 根据回复ID获取单个回复
    @GetMapping("/find_response/{response_id}")
    public Admin_Feedbackresponse_Info getResponseById(@PathVariable("response_id") int response_id) {
        return feedbackresponseService.getResponseById(response_id);
    }

    // 新增反馈回复
    @PostMapping("/add")
    public int addResponse(@RequestBody Admin_Feedbackresponse_Info response) {
        return feedbackresponseService.addResponse(response);
    }

    // 更新反馈回复
    @PutMapping("/update")
    public int updateResponse(@RequestBody Admin_Feedbackresponse_Info response) {
        return feedbackresponseService.updateResponse(response);
    }

    @GetMapping("/findAllWithUser")
    public List<Admin_Feedbackresponse_Info> findAllResponsesWithUser(@RequestParam int page, @RequestParam int pageSize) {
        return feedbackresponseService.findAllResponsesWithUserByPage(page, pageSize);
    }

    @GetMapping("/countAllWithUser")
    public int countAllResponses() {
        return feedbackresponseService.countAllResponses();
    }
}